package com.itheima.wms.controller;

import com.itheima.wms.controller.dto.LoginRequest;
import com.itheima.wms.controller.vo.UserInfoVo;
import com.itheima.wms.service.LoginService;
import com.itheima.wms.utils.Result;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(path = "/users/login")
@RequiredArgsConstructor
public class LoginController {

   private final LoginService loginService;

   @PostMapping
    public Result<UserInfoVo> login(@RequestBody LoginRequest request) {
       UserInfoVo user = loginService.login(request);
       if (user == null) {
           return Result.fail("用户名或密码错误");
       }
       return Result.success(user);
   }
}
